package com.neuedu.controller;


import com.neuedu.pojo.Account;
import com.neuedu.pojo.Protocol;
import com.neuedu.service.IAccountService;
import com.neuedu.service.IProtocolService;
import com.neuedu.util.CommonResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author han
 * @since 2020-09-23
 */
@RestController
@RequestMapping("/account")
public class AccountController {
    @Resource
    IAccountService accountService;



    @GetMapping("/list")
    CommonResult list(Account account) {
        return CommonResult.success(accountService.list(account));
    }

    @PostMapping("/add")
    CommonResult add(Account account) {
        account.setActive(1);
        if(accountService.add(account))
            return CommonResult.success("添加账户成功");
        else
            return CommonResult.failed("此账户已经存在");
    }

    @GetMapping("/getById")
    CommonResult getById(Integer id) {
        return CommonResult.success(accountService.getById(id));
    }

    @PostMapping("/update")
    CommonResult update(Account account) {
        return CommonResult.success(accountService.updateById(account));
    }

    @PostMapping("/del")
    CommonResult del(Account account) {
        account.setActive(0);
        return CommonResult.success(accountService.updateById(account));
    }

    @PostMapping("/batchdel")
    CommonResult batchdel(Integer[] ids) {
        return CommonResult.success(accountService.batchdel(ids));
    }

    @PostMapping("/back")
    CommonResult back(Account account) {
        account.setActive(1);
        return CommonResult.success(accountService.updateById(account));
    }

}
